package com.honey.mybatis.generator.dao.method;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.MethodDecoration;
import com.honey.compilation.java.Parameter;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.types.JDKFullyQualifiedJavaType;
import com.honey.mybatis.generator.AbstractMethod;
import com.honey.mybatis.generator.MybatisPlugin;
import com.honey.mybatis.generator.dao.DaoConstant;
import com.honey.mybatis.generator.page.PageConstant;

public class BaseDaoSelectList1Method extends AbstractMethod {

	private static final FullyQualifiedJavaType RETURN_TYPE = JDKFullyQualifiedJavaType.getListInstance(); 

	private static final String[] JAVA_DOC = new String[]{
		"查询列表。方法的特征如下:<br />",
		"<table  border=\"1\">",
		"  <tr>",
		"    <td align=\"center\">"+PageConstant.PAGE_VARIABLE_NAME+"的total &lt; 0</td>",
		"    <td align=\"center\">"+PageConstant.PAGE_VARIABLE_NAME+"的total = 0</td>",
		"    <td align=\"center\">"+PageConstant.PAGE_VARIABLE_NAME+"中的total &gt; 0</td>",
		"  </tr>",
		"  <tr>",
		"    <td>不使用分页查询</td>",
		"    <td>重新计算符合当前条件记录集的总数量,按照"+PageConstant.PAGE_VARIABLE_NAME+"中指定参数进行分页</td>",
		"    <td>不重新计算符合当前条件记录集的总数量,按照"+PageConstant.PAGE_VARIABLE_NAME+"中指定参数进行分页</td>",
		"  </tr>",
		"</table>",
	} ;
	
	public BaseDaoSelectList1Method(AbstractJavaCompilation clazz,
			MybatisPlugin belongPlugin, IntrospectSchema introspectSchema,
			IntrospectSchemaColumn introspectSchemaColumn) {
		super(clazz, belongPlugin, introspectSchema, introspectSchemaColumn);
	}

	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getMethodName()
	 */
	@Override
	protected String getMethodName() {
		
		return DaoConstant.SELECT_LIST_METHOD_NAME;
	}

	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getParameter()
	 */
	@Override
	protected Parameter[] getParameter() {
		return new Parameter[]{
				new Parameter(JDKFullyQualifiedJavaType.getStringInstance(),"statement","Mybatis映射配置。" ),
				new Parameter(JDKFullyQualifiedJavaType.getStringInstance(),"statementCount","count的Mybatis映射配置。"),
				new Parameter(JDKFullyQualifiedJavaType.getObjectInstance(),"parameter","查询条件"),
				new Parameter(new FullyQualifiedJavaType(mybatisPlugin.getModelTargetPackage()+"."+PageConstant.PAGE_NAME),PageConstant.PAGE_VARIABLE_NAME,"分页"),
			};
	}

	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getJavaDoc()
	 */
	@Override
	protected String[] getJavaDoc() {
		return JAVA_DOC;
	}

	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getMethodDecoration()
	 */
	@Override
	protected MethodDecoration getMethodDecoration() {
//		MethodDecoration answer = super.getMethodDecoration();
//		answer.setVisibility(JavaVisibility.PROTECTED);
//		answer.setFinal(true);
		return super.getDependentModel().getMethodDecoration(null);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getReturnType()
	 */
	@Override
	protected FullyQualifiedJavaType getReturnType() {
		return RETURN_TYPE;
	}

	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getBody()
	 */
	@Override
	protected String[] getBody() {
		return  new String[]{
			"SqlSession session= "+ getInversionModel().call(null,null) ,
			"return selectList(session, statement, statementCount, parameter, page);",
			"//"
		};
	}
}
